// pages/teacher/mine/mineStu/mineStu.js
var app = getApp();
import {teacher_active} from "../../../../asserts/js/common/barList";
import {post} from "../../../../asserts/js/request";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    top: app.globalData.bottom + 'px',
    barList: teacher_active(1),
    title: {
      title1: "班级",
      title2: "学龄"
    },
    alter_show: false,
    tabObj: {
      tabList: [
        {
          name: "班级",
          code: "dance",
          active: true,
          cascadeObj: [],
          cascadeActive: 0,
          templete: "big-buttom"
        },
        {
          name: "学龄",
          code: "level",
          active: false,
          templete: "list-sort",
          cascadeObj: [
            {
              name: "全部",
              code: "",
              active: true
            },
            {
              name: "< 6个月",
              code: "0",
              active: false
            },
            {
              name: "6个月 ~ 1年",
              code: "1",
              active: false
            },
            {
              name: "1年 ~ 2年",
              code: "2",
              active: false
            },
            {
              name: "2年以上",
              code: "3",
              active: false
            }
          ]
        }
      ],
      activeIndex: 0
    },
    stuList: [],
    classId: [],
    studeyTime: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
    this.getAllClass();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectBoxShow: function(){
    this.setData({
      alter_show: true
    })
  },
  alterCancel: function() {
    this.setData({
      alter_show: false
    })
  },
  back: function() {
    wx.navigateBack({
      delta: 0,
    })
  },
  getData: function() {
    let this_ = this;
    post("queryAllStudent", {
      teacherId: app.globalData.teacherInfo.teacherId,
      classId: this.data.classId.join("|"),
      studeyTime: this.data.studeyTime.join("|")
    }).then(data => {
      console.log(data);
      this_.setData({
        stuList: data.studentInfo
      })
    })
  },
  getAllClass: function() {
    post("queryClass",{
      teacherId: app.globalData.teacherInfo.teacherId
    }).then(data => {
      console.log(data)
      var obj = [{
        name: "全部",
        code: "",
        active: true
      }]
      data.classInfo.map(item => {
        var el = {
          name: item.className,
          code: item.classId,
          active: false
        }
        obj.push(el)
      })
      this.setData({
        ["tabObj.tabList[0].cascadeObj"]: obj
      })
    })
  },
  selectSure: function(e) {
    console.log(e.detail.tabList[0].cascadeObj);
    console.log(e.detail.tabList[1].cascadeObj);
    var this_ = this;
    var classId = [];
    if(!e.detail.tabList[0].cascadeObj[0].active){
      e.detail.tabList[0].cascadeObj.map(item => {
        if(item.active) {
          classId.push(item.code)
        }
      })
    }
    var studeyTime = [];
    if(!e.detail.tabList[1].cascadeObj[0].active) {
      e.detail.tabList[1].cascadeObj.map(item => {
        if(item.active) {
          console.log(item.code)
          studeyTime.push(item.code)
        }
      })
    }
    this.setData({
      classId: classId,
      studeyTime: studeyTime,
      alter_show: false
    }, function(){
      this_.getData()
    })
  }
})